<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../../vue.js"></script>
</head>

<body>
    <div class="app">
        <h1>{{title}}</h1>
        <hr>
        <parent></parent>

    </div>

    <template id="parent">
        <div>
            
            <h1>父元素的数据-{{name}}</h1>
        <hr>
        <childone></childone>
        <hr>
        <childtwo :name="name" :age="age"></childtwo>

        </div>

    </template>

    <template id="childone">
        <div>
            <h3>子元素1-{{name}}-{{age}}</h3>
            <button @click="changeage1">点击修改儿子2号的age</button>
        </div>
    </template>

    <template id="childtwo">
        <div>
            <h3>子元素2-{{name}}-{{age}}</h3>
        </div>
    </template>

    <script>
        Vue.component("parent", {
            template: "#parent",
            data() {
                return {
                    name: "不吃鱼的猫",
                    age: 18
                }
            }

        })
        Vue.component("childone", {
            template: "#childone",
            data() {
                return {
                    name: "我是儿子1号",
                    age: 1
                }
            },
            methods: {
                changeage1() {
                    this.$parent.age += 5
                }
            }

        })
        Vue.component("childtwo", {
            template: "#childtwo",
            // data() {
            //     return {
            //         name: "我是儿子2号",
            //         age: 2
            //     }
            // }
            props: ["name", 'age']

        })
        const vm = new Vue({
            data: {
                title: "兄弟改兄弟通过修改父元素的数据进而通过props改子元素的数据"
            }
        }).$mount(".app")
    </script>
</body>

</html>